home *** CD-ROM | disk | FTP | other *** search
/ MacFormat UK 176 / MF_UK_176_1.iso / DiscContents / In the mag / Widgets / Image Shackle 1.1 / Image Shackle / Image Shackle.wdgt / effects.js < prev    next >
Encoding:
Text File  |  2006-08-03  |  3.8 KB  |  163 lines

  1. var eyeShown = false;
  2. var animation = {duration:0, starttime:0, to:1.0, now:0.0, from:0.0, firstElement:null, timer:null};
  3.  
  4. /// Calling these next two will cause the "i" button that flips the
  5. /// widget to fade in and fade out, respectively.
  6. function fadeInEye(){
  7.     if (!eyeShown){
  8.         if (animation.timer != null){
  9.             clearInterval (animation.timer);
  10.             animation.timer  = null;
  11.         }
  12.  
  13.         var starttime = (new Date).getTime() - 13;
  14.  
  15.         animation.duration = 500;
  16.         animation.starttime = starttime;
  17.         animation.firstElement = document.getElementById('eyeFront');
  18.         animation.timer = setInterval ("animate();", 13);
  19.         animation.from = animation.now;
  20.         animation.to = 1.0;
  21.         animate();
  22.         eyeShown = true;
  23.     }
  24. }
  25.  
  26.  
  27. function fadeOutEye(){
  28.     if (eyeShown){
  29.         if (animation.timer != null){
  30.             clearInterval (animation.timer);
  31.             animation.timer  = null;
  32.         }
  33.  
  34.         var starttime = (new Date).getTime() - 13;
  35.  
  36.         animation.duration = 500;
  37.         animation.starttime = starttime;
  38.         animation.firstElement = document.getElementById ('eyeFront');
  39.         animation.timer = setInterval ("animate();", 13);
  40.         animation.from = animation.now;
  41.         animation.to = 0.0;
  42.         animate();
  43.         eyeShown = false;
  44.     }
  45. }
  46.  
  47.  
  48. /// These flip the widget from front to back, and from back to front,
  49. /// respectively.
  50. function doFlipToBack(){
  51.     var front = document.getElementById("front");
  52.     var back = document.getElementById("back");
  53.     
  54.     if(window.widget){
  55.     widget.prepareForTransition("ToBack");
  56.     }
  57.  
  58.     front.style.display="none";
  59.     back.style.display="block";
  60.  
  61.     if(window.widget){
  62.     setTimeout("widget.performTransition();", 0);
  63.     }
  64. }
  65.  
  66.  
  67. function doFlipToFront(){
  68.     var front = document.getElementById("front");
  69.     var back = document.getElementById("back");
  70.  
  71.     if(window.widget){
  72.     widget.prepareForTransition("ToFront");
  73.     }
  74.  
  75. //    document.getElementById("doneButton").src = "done.png";
  76.  
  77.     back.style.display="none";
  78.     front.style.display="block";
  79.     
  80.     if(window.widget){
  81.     setTimeout("widget.performTransition();", 0);
  82.     }
  83. }
  84.  
  85.  
  86.   
  87. random.m=714025; random.a=1366; random.c=150889;
  88. random.seed = (new Date()).getTime()%random.m;
  89. function random() {
  90.   random.seed = (random.seed * random.a + random.c) % random.m;
  91.   return random.seed / random.m;
  92. }
  93.  
  94.  
  95. function giveTheFinger(){
  96.     document.body.style.cursor = "hand"; 
  97. }
  98.  
  99.  
  100. function putItAway(){
  101.     document.body.style.cursor = "default"; 
  102. }
  103.  
  104.  
  105. function animate(){
  106.     var T;
  107.     var ease;
  108.     var time = (new Date).getTime();
  109.  
  110.     T = limit_3(time-animation.starttime, 0, animation.duration);
  111.     
  112.     if (T >= animation.duration){
  113.         clearInterval (animation.timer);
  114.         animation.timer = null;
  115.         animation.now = animation.to;
  116.     
  117.     }else{
  118.         ease = 0.5 - (0.5 * Math.cos(Math.PI * T / animation.duration));
  119.         animation.now = computeNextFloat (animation.from, animation.to, ease);
  120.     }
  121.  
  122.     animation.firstElement.style.opacity = animation.now;
  123. }
  124.  
  125.  
  126. /// Support function for animate()
  127. function limit_3 (a, b, c){
  128.     return a<b ? b : (a>c ? c : a);
  129. }
  130.  
  131.  
  132. /// Support function for animate()
  133. function computeNextFloat (from, to, ease){
  134.     return from + (to - from) * ease;
  135. }
  136.  
  137. function version(){
  138.     var xmlReq = new XMLHttpRequest(); 
  139.     xmlReq.open("GET", "Info.plist", false); 
  140.     xmlReq.send(null); 
  141.     
  142.     var xml = xmlReq.responseXML; 
  143.     var keys = xml.getElementsByTagName("key");
  144.     var ver = "0.0";
  145.  
  146.     for(i=0; i<keys.length; i++){
  147.     if("CFBundleVersion" == keys[i].firstChild.data){
  148.         ver = keys[i].nextSibling.nextSibling.firstChild.data;
  149.         break;
  150.     }
  151.     }
  152.  
  153.     return ver; 
  154. }
  155.  
  156. function showEyeBack(){
  157.     document.getElementById('eyeBack').style.display = "block";
  158. }
  159.  
  160.  
  161. function hideEyeBack(){
  162.     document.getElementById('eyeBack').style.display = "none";
  163. }